//
//  FuzzyImage.swift
//  MovieApp
//
//  Created by SuPeiSen on 2020/11/26.
//

import UIKit

class FuzzImageView: UIImageView {
        
    lazy var context: CIContext = {
        return CIContext(options: nil)
    }()

    public init(image: UIImage?, value: Double) {
        super.init(image: image)
        let inputImage = CIImage(image: image!)
        let filter = CIFilter(name: "CIGaussianBlur")!
        filter.setValue(inputImage, forKey: kCIInputImageKey)
        filter.setValue(value, forKey: kCIInputRadiusKey)
        let outputImage = filter.outputImage!
        let cgImage = context.createCGImage(outputImage, from: CGRect(origin: .zero, size: self.frame.size))
        self.image = UIImage(cgImage: cgImage!)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
